package com.taobao.txc.a.c;

import com.taobao.txc.common.LoggerInit;
import com.taobao.txc.common.LoggerWrap;
import com.taobao.txc.common.config.i;
import com.taobao.txc.common.config.o;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CountDownLatch;
import org.apache.commons.lang.StringUtils;

public class a
{
  private static final LoggerWrap a = LoggerInit.logger;
  private final String b = "vgroup_mapping_";
  private final String c = "com.taobao.txc.grouplist.";
  private boolean d = false;
  private ConcurrentHashMap<String, String> e = new ConcurrentHashMap();
  private volatile List<String> f = new ArrayList();
  private c g;
  
  public a()
  {
    boolean bool = o.b(false);
    if (!bool)
    {
      String str = o.a().a("com.taobao.txc.global.vipcheck", "TXC_GROUP");
      if (!StringUtils.isEmpty(str)) {
        try
        {
          if ((str.equals(Character.valueOf('1'))) || (Boolean.parseBoolean(str) == true)) {
            this.d = true;
          }
        }
        catch (Exception localException) {}
      }
    }
  }
  
  public void a(String paramString, d paramd)
  {
    synchronized (this)
    {
      try
      {
        String str = a(paramString);
        if ((str == null) || (str.length() == 0)) {
          throw new com.taobao.txc.common.b.c("can't fetch real group name from diamond!vgroup_mapping_" + paramString);
        }
        b(str, paramd);
      }
      catch (Exception localException)
      {
        throw com.taobao.txc.common.b.c.a(localException);
      }
    }
    o.a().a("vgroup_mapping_" + paramString, "TXC_GROUP", new b(this));
  }
  
  public List<String> a()
  {
    return this.f;
  }
  
  public void a(List<String> paramList)
  {
    this.f = paramList;
  }
  
  public String a(String paramString)
  {
    return o.a().a("vgroup_mapping_" + paramString, "TXC_GROUP", 60000L);
  }
  
  public boolean a(String paramString1, String paramString2, com.taobao.txc.common.util.b.a parama)
  {
    synchronized (com.taobao.txc.a.b.g.a().f)
    {
      if (com.taobao.txc.a.b.g.a().f.size() < 2) {
        return false;
      }
      if ((paramString2 != null) && (!paramString2.equals(com.taobao.txc.a.b.g.a().f.get(0)))) {
        return false;
      }
      Collections.reverse(com.taobao.txc.a.b.g.a().f);
      int i = 0;
      StringBuilder localStringBuilder = new StringBuilder();
      Iterator localIterator = com.taobao.txc.a.b.g.a().f.iterator();
      while (localIterator.hasNext())
      {
        String str = (String)localIterator.next();
        if (i != 0) {
          localStringBuilder.append('\n');
        } else {
          i = 1;
        }
        localStringBuilder.append(str);
      }
      try
      {
        o.a().a("vgroup_mapping_" + paramString1, "TXC_GROUP", localStringBuilder.toString(), parama);
      }
      catch (Exception localException)
      {
        a.warn("publish vgroup_mapping_" + paramString1 + " to " + localStringBuilder + " fail.");
        Collections.reverse(com.taobao.txc.a.b.g.a().f);
        return false;
      }
      a.a("vgroup_mapping_" + paramString1 + " changed to " + localStringBuilder);
      return true;
    }
  }
  
  public synchronized void b(String paramString, d paramd)
  {
    if (StringUtils.isEmpty(paramString)) {
      return;
    }
    List localList1 = com.taobao.txc.common.util.c.g.a(paramString);
    if ((localList1 == null) || (localList1.size() == 0)) {
      return;
    }
    synchronized (com.taobao.txc.a.b.g.a().f)
    {
      com.taobao.txc.a.b.g.a().f.clear();
      for (int i = 0; i < localList1.size(); i++) {
        com.taobao.txc.a.b.g.a().f.add(localList1.get(i));
      }
    }
    ??? = "com.taobao.txc.grouplist." + (String)localList1.get(0);
    CountDownLatch localCountDownLatch = new CountDownLatch(1);
    if (this.g != null)
    {
      paramd = c.a(this.g);
      c.b(this.g);
      if (!o.a) {
        i.b().a((String)???, "TXC_GROUP", this.g);
      }
    }
    if (paramd == null) {
      throw new RuntimeException("watcher is null");
    }
    this.g = new c(this, localCountDownLatch, paramd, null);
    o.a().a((String)???, "TXC_GROUP", this.g);
    try
    {
      String str1 = o.a().a((String)???, "TXC_GROUP", 60000L);
      if (str1 != null)
      {
        List localList2 = c.a(this.g, str1);
        if (localList2 != null)
        {
          Iterator localIterator = localList2.iterator();
          while (localIterator.hasNext())
          {
            String str2 = (String)localIterator.next();
            com.taobao.txc.a.b.g.a().g.put(str2, localList1.get(0));
          }
        }
      }
      else
      {
        throw new com.taobao.txc.common.b.c("grouplist is null, dataId:" + (String)???);
      }
    }
    catch (IOException localIOException)
    {
      a.a(com.taobao.txc.common.b.b.a, localIOException);
    }
    localCountDownLatch.await();
  }
}


/* Location:           C:\Users\ibm\Downloads\txc-yun-sample (1)\txc-yun-sample\lib\txc-client-2.0.72.jar
 * Qualified Name:     com.taobao.txc.a.c.a
 * JD-Core Version:    0.7.0.1
 */